import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PurchasePlanVO, PurchasePlanForm, PurchasePlanQuery } from '@/api/lingxing/purchasePlan/types';

/**
 * 查询领星采购计划列表
 * @param query
 * @returns {*}
 */

export const listPurchasePlan = (query?: PurchasePlanQuery): AxiosPromise<PurchasePlanVO[]> => {
  return request({
    url: '/lingxing/purchasePlan/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询领星采购计划详细
 * @param id
 */
export const getPurchasePlan = (id: string | number): AxiosPromise<PurchasePlanVO> => {
  return request({
    url: '/lingxing/purchasePlan/' + id,
    method: 'get'
  });
};

/**
 * 新增领星采购计划
 * @param data
 */
export const addPurchasePlan = (data: PurchasePlanForm) => {
  return request({
    url: '/lingxing/purchasePlan',
    method: 'post',
    data: data
  });
};

/**
 * 修改领星采购计划
 * @param data
 */
export const updatePurchasePlan = (data: PurchasePlanForm) => {
  return request({
    url: '/lingxing/purchasePlan',
    method: 'put',
    data: data
  });
};

/**
 * 删除领星采购计划
 * @param id
 */
export const delPurchasePlan = (id: string | number | Array<string | number>) => {
  return request({
    url: '/lingxing/purchasePlan/' + id,
    method: 'delete'
  });
};

/**
 * 同步领星仓库列表
 * @returns {*}
 */
export const syncData = (data?: PurchasePlanQuery) => {
  return request({
    url: '/lingxing/purchasePlan/syncData',
    method: 'post',
    data: data
  });
};

export const getNewestUpdateTime = () => {
  return request({
    url: '/lingxing/purchasePlan/getNewestUpdateTime',
    method: 'get'
  });
};
